package main

import (
	"bufio"
	"fmt"
	"net"
	"os"
	"strings"
)

func main() {
	fmt.Println("客户端启动")
	conn, err := net.Dial("tcp", "127.0.0.1:8888")
	if err != nil {
		fmt.Println("客户端建立连接失败：", err)
		return
	}
	fmt.Println("客户端建立连接成功")
	defer conn.Close()
	// 标准输入[终端]
	reader := bufio.NewReader(os.Stdin)

	for true {
		line, err := reader.ReadString('\n')
		if err != nil {
			fmt.Println("reader error = ", err)
		}
		line = strings.Trim(line, "\r\n")
		if line == "exit" {
			fmt.Printf("客户端退出")

		}
		n, err := conn.Write([]byte(line))
		if err != nil {
			fmt.Println("Write error = ", err)
			return
		}
		fmt.Printf("客户端发送字节数 = %v \n", n)
	}

}
